import { entryInfoUrl, entrySaveUrl } from '../../../../api/individual'
import { post } from '../../../../utils/index'

Page({
  data: {
    info: {},
    list: [{ id: 0, title: '接收档案' }, { id: 1, title: '落户' }],
    business: []
  },
  async loadData () { // 获取人员信息
    const { data } = await post(entryInfoUrl)
    let business = []
    if (data.business.length) {
      business = data.business.split(',')
    }
    this.setData({ info: data, business })
  },
  async save () {
    const { info, business } = this.data
    info.business = business.join(',')
    await post(entrySaveUrl, info)
    wx.navigateBack({})
  },
  onChange ({ detail }) { // 选中回调
    this.setData({ business: detail })
  },
  toggle ({ currentTarget, dataset }) {
    const { index } = currentTarget.dataset || dataset
    const checkbox = this.selectComponent(`.checkboxes-${index}`)
    checkbox.toggle()
  },
  back () {
    wx.navigateBack({})
  },
  onLoad () {
    this.loadData()
  }
})